package com.ruoyi.report_jl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_jl.domain.bo.ReportJlKfmdhslsyjlbBsInfoBo;
import com.ruoyi.report_jl.domain.vo.ReportJlKfmdhslsyjlbBsInfoVo;
import com.ruoyi.report_jl.domain.ReportJlKfmdhslsyjlbBsInfo;
import com.ruoyi.report_jl.mapper.ReportJlKfmdhslsyjlbBsInfoMapper;
import com.ruoyi.report_jl.service.IReportJlKfmdhslsyjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 矿粉密度、含水率、亲水系数、加热安定性试验检测记录Service业务层处理
 *
 * @author tll
 * @date 2024-06-27
 */
@RequiredArgsConstructor
@Service
public class ReportJlKfmdhslsyjlbBsInfoServiceImpl implements IReportJlKfmdhslsyjlbBsInfoService {

    private final ReportJlKfmdhslsyjlbBsInfoMapper baseMapper;

    /**
     * 查询矿粉密度、含水率、亲水系数、加热安定性试验检测记录
     */
    @Override
    @FIllBasicInfo
    public ReportJlKfmdhslsyjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询矿粉密度、含水率、亲水系数、加热安定性试验检测记录列表
     */
    @Override
    public TableDataInfo<ReportJlKfmdhslsyjlbBsInfoVo> queryPageList(ReportJlKfmdhslsyjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportJlKfmdhslsyjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportJlKfmdhslsyjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询矿粉密度、含水率、亲水系数、加热安定性试验检测记录列表
     */
    @Override
    public List<ReportJlKfmdhslsyjlbBsInfoVo> queryList(ReportJlKfmdhslsyjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportJlKfmdhslsyjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportJlKfmdhslsyjlbBsInfo> buildQueryWrapper(ReportJlKfmdhslsyjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportJlKfmdhslsyjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportJlKfmdhslsyjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportJlKfmdhslsyjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportJlKfmdhslsyjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportJlKfmdhslsyjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportJlKfmdhslsyjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportJlKfmdhslsyjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportJlKfmdhslsyjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportJlKfmdhslsyjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportJlKfmdhslsyjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, ReportJlKfmdhslsyjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportJlKfmdhslsyjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportJlKfmdhslsyjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportJlKfmdhslsyjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportJlKfmdhslsyjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportJlKfmdhslsyjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportJlKfmdhslsyjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportJlKfmdhslsyjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportJlKfmdhslsyjlbBsInfo::getBaobmc, bo.getBaobmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportJlKfmdhslsyjlbBsInfo::getBaobbh, bo.getBaobbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportJlKfmdhslsyjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportJlKfmdhslsyjlbBsInfo::getJiancr, bo.getJiancr());
        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportJlKfmdhslsyjlbBsInfo::getJilr, bo.getJilr());
        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportJlKfmdhslsyjlbBsInfo::getFuhr, bo.getFuhr());
        lqw.eq(bo.getRiq() != null, ReportJlKfmdhslsyjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportJlKfmdhslsyjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportJlKfmdhslsyjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportJlKfmdhslsyjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getMidsycsItem1()), ReportJlKfmdhslsyjlbBsInfo::getMidsycsItem1, bo.getMidsycsItem1());
        lqw.eq(bo.getMidsygzzl1Item1() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsygzzl1Item1, bo.getMidsygzzl1Item1());
        lqw.eq(bo.getMidsygzzl2Item1() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsygzzl2Item1, bo.getMidsygzzl2Item1());
        lqw.eq(bo.getMidsycdsItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsycdsItem1, bo.getMidsycdsItem1());
        lqw.eq(bo.getMidsyzdsItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsyzdsItem1, bo.getMidsyzdsItem1());
        lqw.eq(bo.getMidsykfmdczItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsykfmdczItem1, bo.getMidsykfmdczItem1());
        lqw.eq(bo.getMidsyswdItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsyswdItem1, bo.getMidsyswdItem1());
        lqw.eq(bo.getMidsysmdItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsysmdItem1, bo.getMidsysmdItem1());
        lqw.eq(bo.getMidsyxdmdczItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsyxdmdczItem1, bo.getMidsyxdmdczItem1());
        lqw.eq(StringUtils.isNotBlank(bo.getMidsycsItem2()), ReportJlKfmdhslsyjlbBsInfo::getMidsycsItem2, bo.getMidsycsItem2());
        lqw.eq(bo.getMidsygzzl1Item2() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsygzzl1Item2, bo.getMidsygzzl1Item2());
        lqw.eq(bo.getMidsygzzl2Item2() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsygzzl2Item2, bo.getMidsygzzl2Item2());
        lqw.eq(bo.getMidsycdsItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsycdsItem2, bo.getMidsycdsItem2());
        lqw.eq(bo.getMidsyzdsItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsyzdsItem2, bo.getMidsyzdsItem2());
        lqw.eq(bo.getMidsykfmdczItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsykfmdczItem2, bo.getMidsykfmdczItem2());
        lqw.eq(bo.getMidsyswdItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsyswdItem2, bo.getMidsyswdItem2());
        lqw.eq(bo.getMidsysmdItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsysmdItem2, bo.getMidsysmdItem2());
        lqw.eq(bo.getMidsyxdmdczItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsyxdmdczItem2, bo.getMidsyxdmdczItem2());
        lqw.eq(bo.getMidsykfmdczPjz() != null, ReportJlKfmdhslsyjlbBsInfo::getMidsykfmdczPjz, bo.getMidsykfmdczPjz());
        lqw.eq(bo.getHanslsycsItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsycsItem1, bo.getHanslsycsItem1());
        lqw.eq(bo.getHanslsyhstzlItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhstzlItem1, bo.getHanslsyhstzlItem1());
        lqw.eq(bo.getHanslsyhgtzlItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhgtzlItem1, bo.getHanslsyhgtzlItem1());
        lqw.eq(bo.getHanslsyhzlItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhzlItem1, bo.getHanslsyhzlItem1());
        lqw.eq(bo.getHanslsyhslczItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhslczItem1, bo.getHanslsyhslczItem1());
        lqw.eq(bo.getHanslsycsItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsycsItem2, bo.getHanslsycsItem2());
        lqw.eq(bo.getHanslsyhstzlItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhstzlItem2, bo.getHanslsyhstzlItem2());
        lqw.eq(bo.getHanslsyhgtzlItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhgtzlItem2, bo.getHanslsyhgtzlItem2());
        lqw.eq(bo.getHanslsyhzlItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhzlItem2, bo.getHanslsyhzlItem2());
        lqw.eq(bo.getHanslsyhslczItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhslczItem2, bo.getHanslsyhslczItem2());
        lqw.eq(bo.getHanslsyhslczPjz() != null, ReportJlKfmdhslsyjlbBsInfo::getHanslsyhslczPjz, bo.getHanslsyhslczPjz());
        lqw.eq(bo.getQinsxssycsItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getQinsxssycsItem1, bo.getQinsxssycsItem1());
        lqw.eq(bo.getQinsxssyszcdwtjItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getQinsxssyszcdwtjItem1, bo.getQinsxssyszcdwtjItem1());
        lqw.eq(bo.getQinsxssymyzcdwtjItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getQinsxssymyzcdwtjItem1, bo.getQinsxssymyzcdwtjItem1());
        lqw.eq(bo.getQinsxssysyqsxtczItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getQinsxssysyqsxtczItem1, bo.getQinsxssysyqsxtczItem1());
        lqw.eq(bo.getQinsxssycsItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getQinsxssycsItem2, bo.getQinsxssycsItem2());
        lqw.eq(bo.getQinsxssyszcdwtjItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getQinsxssyszcdwtjItem2, bo.getQinsxssyszcdwtjItem2());
        lqw.eq(bo.getQinsxssymyzcdwtjItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getQinsxssymyzcdwtjItem2, bo.getQinsxssymyzcdwtjItem2());
        lqw.eq(bo.getQinsxssysyqsxtczItem2() != null, ReportJlKfmdhslsyjlbBsInfo::getQinsxssysyqsxtczItem2, bo.getQinsxssysyqsxtczItem2());
        lqw.eq(bo.getJiaradxsycsItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getJiaradxsycsItem1, bo.getJiaradxsycsItem1());
        lqw.eq(bo.getJiaradxsysyzlItem1() != null, ReportJlKfmdhslsyjlbBsInfo::getJiaradxsysyzlItem1, bo.getJiaradxsysyzlItem1());
        lqw.eq(bo.getH11() != null, ReportJlKfmdhslsyjlbBsInfo::getH11, bo.getH11());
        lqw.eq(bo.getH12()!= null, ReportJlKfmdhslsyjlbBsInfo::getH12, bo.getH12());
        lqw.eq(bo.getHeh11Id()!= null, ReportJlKfmdhslsyjlbBsInfo::getHeh11Id, bo.getHeh11Id());
        lqw.eq(bo.getHeh12Id()!= null, ReportJlKfmdhslsyjlbBsInfo::getHeh12Id, bo.getHeh12Id());
        lqw.eq(StringUtils.isNotBlank(bo.getJiaradxsyysbhqkItem1()), ReportJlKfmdhslsyjlbBsInfo::getJiaradxsyysbhqkItem1, bo.getJiaradxsyysbhqkItem1());
        return lqw;
    }

    /**
     * 新增矿粉密度、含水率、亲水系数、加热安定性试验检测记录
     */
    @Override
    public Boolean insertByBo(ReportJlKfmdhslsyjlbBsInfoBo bo) {
        ReportJlKfmdhslsyjlbBsInfo add = BeanUtil.toBean(bo, ReportJlKfmdhslsyjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改矿粉密度、含水率、亲水系数、加热安定性试验检测记录
     */
    @Override
    public Boolean updateByBo(ReportJlKfmdhslsyjlbBsInfoBo bo) {
        ReportJlKfmdhslsyjlbBsInfo update = BeanUtil.toBean(bo, ReportJlKfmdhslsyjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportJlKfmdhslsyjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除矿粉密度、含水率、亲水系数、加热安定性试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
